<template>
  <div class="warp" id="app_box">
    <router-view v-slot="{ Component }">
      <keep-alive>
        <component v-if="route.meta.keepAlive" :key="route.name" :is="Component"></component>
      </keep-alive>
      <component v-if="!route.meta.keepAlive" :key="route.name" :is="Component"></component>
    </router-view>
    <van-back-top target=".warp" immediate bottom="100" :offset="400" />
  </div>
  <!-- 签名弹窗 -->
  <van-popup :close-on-click-overlay="false" v-model:show="showSinger" round :style="{ padding: '20px 34px' }">
    <div class="singer_value background_box">{{ t('toast.pleaseSignFirst') }}</div>
    <div class="btn_two">
      <van-button @click="cancelSinger"> {{ t('Cancel') }}</van-button>
      <van-button type="primary" :loading="loading" @click="getSinger">
        {{ t('sign') }}</van-button>
    </div>
  </van-popup>
</template>
<script setup>
import { ethers } from "ethers";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute()
import { ref, onMounted, onUnmounted, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { showToast } from "vant";
import { useStore } from "vuex";
import eth from "../utils/eth";
import { switchNetwork } from "@/utils/eth.js";
const store = useStore();
const loading = ref(false);
const showSinger = ref(false);
const { locale, t } = useI18n();
eth.linkWallet()
const fn = () => {
  ethereum.on("accountsChanged", async function (accounts) {
    store.commit('changeAddress', accounts[0])
    eth.linkWallet()
    initData()
  });
  window.ethereum.on("chainChanged", async(chain) => {
    await switchNetwork(chain);
    eth.linkWallet()
  });
};
const initData = async ()=>{
}
initData()
// 定时循环获取单聊数据
const intTime = setInterval(() => {
}, 5 * 1000 * 60)
onUnmounted(() => {
  clearInterval(intTime)
})
onMounted(() => {
  fn();
});
</script>
<style>
#app_box{
}
</style>
